package lg.iu.transforms.input;

import lg.iu.ClassHooks;
import lg.iu.FieldHooks;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;

import wolf.iu.framework.ClassContainer;
import wolf.iu.framework.ClassesHandler;
import wolf.iu.framework.HooksList;
import wolf.iu.framework.hooks.AbstractTransform;
import wolf.iu.framework.hooks.HookState;

public class CanvasTransform extends AbstractTransform {

    @Override
    public HookState execute(final ClassesHandler ch, final ClassContainer cc,
            final HooksList hooks) {
        final ClassNode node = cc.getNode();
        //node.interfaces.contains("java/awt/event/MouseListener")
        for (final Object o : node.fields) {
            final FieldNode fn = (FieldNode) o;
            if (fn.desc.equals("Ljava/awt/Canvas;") && (fn.access & Opcodes.ACC_STATIC) != 0) {
                hooks.setFieldHook(ClassHooks.Client, FieldHooks.GetCanvas,
                        new FieldInsnNode(Opcodes.GETSTATIC, node.name, fn.name, fn.desc));
                return HookState.Found;
            }
        }
        //MouseListener ml = null;
        return HookState.WrongClass;
    }

}
